package com.snopy.leetcode.index1_1000.index1_100;



/**
 * @author snopy
 * @version 1.0.0
 * @classname Question83
 * @description 删除排序链表中的重复元素
 *
 * 给定一个已排序的链表的头 head ， 删除所有重复的元素，使每个元素只出现一次 。返回 已排序的链表 。
 * @email 77912204@qq.com
 * @date 2022/04/21 20:47
 */
public class Question83 {
    public static void main(String[] args) {
        ListNode head = new ListNode(1,new ListNode(1,new ListNode(2)));
        ListNode node = deleteDuplicates(head);
        while (node!=null){
            System.out.println(node.val);
            node = node.next;
        }
    }
    public static ListNode deleteDuplicates(ListNode head) {
        if (head == null){
            return null;
        }
        ListNode curNode = head;
        ListNode nextNode = null;
        while (curNode.next!=null){
            nextNode = curNode.next;
            if (curNode.val == nextNode.val){
                curNode.next = nextNode.next;
            }else {
                curNode = nextNode;
            }
        }
        return head;
    }
}

class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
